package com.zlb.demo.config;

import com.zlb.demo.interceptor.PaginationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description
 * @Author zlb
 * @Since 2024-03-19 22:00:26
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 自定义分页器
    @Autowired
    private PaginationInterceptor paginationInterceptor;

    // 配置跨域
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true) // 是否发送Cookie
                .allowedHeaders("*") // 放行哪些原始请求头部信息
                // .allowedOrigins("*") // 放行哪些原始域
                .allowedOriginPatterns("*") // 放行匹配上的原始域
                .allowedMethods("*"); // 放行哪些请求方式
    }

    /**
     * 添加拦截器,处理分页信息
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(paginationInterceptor);
    }

}
